/**
 * 
 */
package us.gaaoc.framework.webapp.controllers;


import java.util.Map;

import javax.faces.component.UIParameter;

import org.apache.log4j.Logger;

import us.gaaoc.framework.businessmodel.Filing;

/**
 * @author artripa
 *
 */
public class ClerkFilingsTableController extends BaseTableController {

	private Logger log = Logger.getLogger(ClerkFilingsTableController.class);
	private UIParameter caseDetailsPageClicked;
	
	@Override
	public int getRole() {
		return -1;
	}
	
	@Override
	public boolean isFilterPersonalCases() {
		return false;
	}
	
	@Override
	public void setFilterPersonalCases(boolean filterPersonalCases) {
	
	}
	
	private boolean renderforClerksAuthority;
	
	
	public boolean isRenderforClerksAuthority() {
		return renderforClerksAuthority;
	}

	public void setRenderforClerksAuthority(boolean renderforClerksAuthority) {
		this.renderforClerksAuthority = renderforClerksAuthority;
	}

	public ClerkFilingsTableController()
	{
		if(this.getModelFacade().findCourtByUuid(this.getCourtUuid().toString()).isThruClerksAuthority())
		{
			this.setRenderforClerksAuthority(false);
		}
		else
		{
			this.setRenderforClerksAuthority(true);
		}
	}
	
	/* Navigation */
	
	/**
	 * Navigates the user to the case details page. 
	 * @requestparam caseUuid the UUID of the case.
	*/
	
	
	@SuppressWarnings("unchecked")
	public String gotoCaseDetailsPage() {
		Map<String, String> sessionMap = this.getSessionMap();
		Map requestMap = this.getFacesContext().getExternalContext().getRequestParameterMap();
		String caseUuid = ((String) requestMap.get("caseUuid"));
		sessionMap.put("caseUuid", caseUuid);
			 	
	 	sessionMap.put("from", "MainPage");
	 	
	 	return "gotoCaseDetailsPage";
	}
	
	
	/**
	 * Navigates the user to the trash can page.
	 */
	public String gotoTrashCanPage() {
		return "trashcanPage";
	}
	
	/**
	 * Navigates the user to the existing filing page.
	 */
	public String gotoExistingFilingPage() {
		return "existingFilingPage";
	}
	
	/**
	 * Navigates the user to the search page.  Also, saves the current page
	 * to the session map.
	 */
	@SuppressWarnings("unchecked")
	public String gotoSearchPage() {
		Map<String, String> sessionMap = this.getSessionMap();
	 	sessionMap.put("from", "clerkMainPage");
		return "gotoSearchPage";
	}
	
	/**
	 * In the future, this page will navigate the user to the reports page. Currently,
	 * the method simply returns the user to the current page.
	 */
	@SuppressWarnings("unchecked")
	public String gotoReportsPage() {
		Map<String, String> sessionMap = this.getSessionMap();
	 	sessionMap.put("from", "clerkMainPage");
		return "gotoReportsPage";
	}

	/**
	 * Navigates to the history of the case
	 * @requestparam caseUuid the UUID of the case record
	 */
	@SuppressWarnings("unchecked")
	public String gotoHistoryPage() {
		Map<String, String> sessionMap = this.getSessionMap();
		Map requestMap = this.getFacesContext().getExternalContext()
				.getRequestParameterMap();
		String caseUuid = ((String) requestMap.get("caseUuid"));
		sessionMap.put("caseUuid", caseUuid);
		sessionMap.put("from", "clerkMainPage");
		return "gotoCaseHistoryPage";
	}
	

	
	

	public void setCaseDetailsPageClicked(UIParameter caseDetailsPageClicked) {
		this.caseDetailsPageClicked = caseDetailsPageClicked;
	}

	public UIParameter getCaseDetailsPageClicked() {
		return caseDetailsPageClicked;
	}

	public void clearCase(String caseUuid ) {
		Map requestMap = this.getFacesContext().getExternalContext()
				.getRequestParameterMap();	
		this.getModelFacade().updateCaseRecordForClearCase(caseUuid, true,
				this.getCourtUuid());		
	}




}
